package cn.gailvlun.gll.pay;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        IWXAPI api = WXAPIFactory.createWXAPI(this, UniPay.wechatAppId, false);
        api.registerApp(UniPay.wechatAppId);
        api.handleIntent(getIntent(), this);
        finish();
    }

    public static UniPayListener uniPayListener;

    @Override
    public void onReq(BaseReq baseReq) {
    }

    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case 0: {
                uniPayListener.onSuccess();
                break;
            }
            case -1: {
                uniPayListener.onError("其他错误");
                break;
            }
            case -2: {
                uniPayListener.onError("用户取消");
                break;
            }
            default: {
                uniPayListener.onError("未知错误");
            }
        }
        uniPayListener = null;
    }
}
